<template>
  <div class="login-form">
    <el-form ref="form" :model="form" :rules="rules" label-position="left" label-width="80px" class="form-box">
      <el-form-item label="账号" prop="username">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="password" v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [{ required: true, message: '请输入账号', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      }
    };
  },
  methods: {
    submitForm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          // 表单校验通过，提交登录请求
          console.log('登录信息：', this.form);
        }
      });
    }
  }
};
</script>

<style lang="less" scoped>
.login-form {
  height: 100vh; // 占满整个视窗高度
  display: flex;
  justify-content: center;
  align-items: center;
  
  .form-box {
    width: 400px;
    padding: 20px;
    border-radius: 5px;
    background-color: #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  }
}
</style>